/**
 * @param {string} s
 * @param {string} t
 * @return {boolean}
 */
// Map比对
var isAnagram = function (s, t) {
    const dict_s = new Map();
    const dict_t = new Map();

    const len_s = s.length;
    const len_t = t.length;

    if (len_s != len_t) {
        return false;
    }

    for (let i = 0; i < len_s; i++) {
        if (dict_s.has(s[i])) {
            dict_s.set(s[i], dict_s.get(s[i]) + 1);
        } else {
            dict_s.set(s[i], 1);
        }
    }
    for (let i = 0; i < len_t; i++) {
        if (dict_t.has(t[i])) {
            dict_t.set(t[i], dict_t.get(t[i]) + 1);
        } else {
            dict_t.set(t[i], 1);
        }
    }

    for (let characters of dict_s.keys()) {
        if (dict_s.get(characters) != dict_t.get(characters)) {
            return false
        }
    }
    return true;
};

// 26个字母对应0-25的数组
var isAnagram = function (s, t) {
    const len_s = s.length;
    const len_t = t.length;

    if (len_s != len_t) {
        return false;
    }

    const arr = new Array(26).fill(0);
    for (let i = 0; i < len_s; i++) {
        arr[s[i].codePointAt() - 'a'.codePointAt()] += 1;
    }
    for (let i = 0; i < len_t; i++) {
        arr[t[i].codePointAt() - 'a'.codePointAt()] -= 1;
        if (arr[t[i].codePointAt() - 'a'.codePointAt()] < 0) {
            return false;
        }
    }
    return true;
};